﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using Command;
using Structure.Interfaces;
using System.Web.UI.WebControls;
using Structure.Objects;

namespace Application.Controls
{
    public partial class Login : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string pLogin = TextBox1.Text;
            string pPass = TextBox2.Text;
            string pFio = null;
            iCommand command = BuildCommand.Build();
            string pRole = command.Login(pLogin, pPass, ref pFio);
            if (pRole == "0")
            {
                Label3.Visible = true;
            }
            else
            {
                Label3.Visible = false;
                Label1.Visible = false;
                Button1.Visible = false;
                TextBox1.Visible = false;
                TextBox2.Visible = false;
                Label2.Text = "Добро Пожаловать, " + pFio + "!";

                if (pRole == "1")
                {
                    User.Cur_User = new Manager(pLogin, pPass, pFio);
                }
                if (pRole == "2")
                {
                    User.Cur_User = new Commiter(pLogin, pPass, pFio);
                }
                if (pRole == "3")
                {
                    User.Cur_User = new Observer(pLogin, pPass, pFio);
                }
            }


            
        }
    }
}